home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / doom / chasecam.zip / QC106.ZIP / WEAPONS.QC < prev    next >
Text File  |  1997-04-20  |  27KB  |  1,357 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25.  
  26.     // ### chasecam mod ###
  27.     // Stuff for Bort's hook (chasecam tag used for consistency
  28.     // in text searches for this mod)
  29.     precache_sound ("shambler/smack.wav");
  30.     precache_sound ("blob/land1.wav");
  31.     precache_sound ("hook/chain1.wav");
  32.     precache_sound ("hook/chain2.wav");
  33.     precache_sound ("hook/retract.wav");
  34.  
  35. };
  36.  
  37. float() crandom =
  38. {
  39.     return 2*(random() - 0.5);
  40. };
  41.  
  42. /*
  43. ================
  44. W_FireAxe
  45. ================
  46. */
  47. void() W_FireAxe =
  48. {
  49.     local    vector    source;
  50.     local    vector    org;
  51.  
  52.     makevectors (self.v_angle);
  53.     source = self.origin + '0 0 16';
  54.     traceline (source, source + v_forward*64, FALSE, self);
  55.     if (trace_fraction == 1.0)
  56.         return;
  57.     
  58.     org = trace_endpos - v_forward*4;
  59.  
  60.     if (trace_ent.takedamage)
  61.     {
  62.         trace_ent.axhitme = 1;
  63.         SpawnBlood (org, '0 0 0', 20);
  64.         T_Damage (trace_ent, self, self, 20);
  65.     }
  66.     else
  67.     {    // hit wall
  68.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  69.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  70.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  71.         WriteCoord (MSG_BROADCAST, org_x);
  72.         WriteCoord (MSG_BROADCAST, org_y);
  73.         WriteCoord (MSG_BROADCAST, org_z);
  74.     }
  75. };
  76.  
  77.  
  78. //============================================================================
  79.  
  80.  
  81. vector() wall_velocity =
  82. {
  83.     local vector    vel;
  84.     
  85.     vel = normalize (self.velocity);
  86.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  87.     vel = vel + 2*trace_plane_normal;
  88.     vel = vel * 200;
  89.     
  90.     return vel;
  91. };
  92.  
  93.  
  94. /*
  95. ================
  96. SpawnMeatSpray
  97. ================
  98. */
  99. void(vector org, vector vel) SpawnMeatSpray =
  100. {
  101.     local    entity missile, mpuff;
  102.     local    vector    org;
  103.  
  104.     missile = spawn ();
  105.     missile.owner = self;
  106.     missile.movetype = MOVETYPE_BOUNCE;
  107.     missile.solid = SOLID_NOT;
  108.  
  109.     makevectors (self.angles);
  110.  
  111.     missile.velocity = vel;
  112.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  113.  
  114.     missile.avelocity = '3000 1000 2000';
  115.     
  116. // set missile duration
  117.     missile.nextthink = time + 1;
  118.     missile.think = SUB_Remove;
  119.  
  120.     setmodel (missile, "progs/zom_gib.mdl");
  121.     setsize (missile, '0 0 0', '0 0 0');        
  122.     setorigin (missile, org);
  123. };
  124.  
  125. /*
  126. ================
  127. SpawnBlood
  128. ================
  129. */
  130. void(vector org, vector vel, float damage) SpawnBlood =
  131. {
  132.     particle (org, vel*0.1, 73, damage*2);
  133. };
  134.  
  135. /*
  136. ================
  137. spawn_touchblood
  138. ================
  139. */
  140. void(float damage) spawn_touchblood =
  141. {
  142.     local vector    vel;
  143.  
  144.     vel = wall_velocity () * 0.2;
  145.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  146. };
  147.  
  148.  
  149. /*
  150. ================
  151. SpawnChunk
  152. ================
  153. */
  154. void(vector org, vector vel) SpawnChunk =
  155. {
  156.     particle (org, vel*0.02, 0, 10);
  157. };
  158.  
  159. /*
  160. ==============================================================================
  161.  
  162. MULTI-DAMAGE
  163.  
  164. Collects multiple small damages into a single damage
  165.  
  166. ==============================================================================
  167. */
  168.  
  169. entity    multi_ent;
  170. float    multi_damage;
  171.  
  172. void() ClearMultiDamage =
  173. {
  174.     multi_ent = world;
  175.     multi_damage = 0;
  176. };
  177.  
  178. void() ApplyMultiDamage =
  179. {
  180.     if (!multi_ent)
  181.         return;
  182.     T_Damage (multi_ent, self, self, multi_damage);
  183. };
  184.  
  185. void(entity hit, float damage) AddMultiDamage =
  186. {
  187.     if (!hit)
  188.         return;
  189.     
  190.     if (hit != multi_ent)
  191.     {
  192.         ApplyMultiDamage ();
  193.         multi_damage = damage;
  194.         multi_ent = hit;
  195.     }
  196.     else
  197.         multi_damage = multi_damage + damage;
  198. };
  199.  
  200. /*
  201. ==============================================================================
  202.  
  203. BULLETS
  204.  
  205. ==============================================================================
  206. */
  207.  
  208. /*
  209. ================
  210. TraceAttack
  211. ================
  212. */
  213. void(float damage, vector dir) TraceAttack =
  214. {
  215.     local    vector    vel, org;
  216.     
  217.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  218.     vel = vel + 2*trace_plane_normal;
  219.     vel = vel * 200;
  220.  
  221.     org = trace_endpos - dir*4;
  222.  
  223.     if (trace_ent.takedamage)
  224.     {
  225.         SpawnBlood (org, vel*0.2, damage);
  226.         AddMultiDamage (trace_ent, damage);
  227.     }
  228.     else
  229.     {
  230.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  231.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  232.         WriteCoord (MSG_BROADCAST, org_x);
  233.         WriteCoord (MSG_BROADCAST, org_y);
  234.         WriteCoord (MSG_BROADCAST, org_z);
  235.     }
  236. };
  237.  
  238. /*
  239. ================
  240. FireBullets
  241.  
  242. Used by shotgun, super shotgun, and enemy soldier firing
  243. Go to the trouble of combining multiple pellets into a single damage call.
  244. ================
  245. */
  246. void(float shotcount, vector dir, vector spread) FireBullets =
  247. {
  248.     local    vector direction;
  249.     local    vector    src;
  250.  
  251.     makevectors(self.v_angle);
  252.  
  253.     src = self.origin + v_forward*10;
  254.     src_z = self.absmin_z + self.size_z * 0.7;
  255.  
  256.     ClearMultiDamage ();
  257.     while (shotcount > 0)
  258.     {
  259.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  260.  
  261.         traceline (src, src + direction*2048, FALSE, self);
  262.         if (trace_fraction != 1.0)
  263.             TraceAttack (4, direction);
  264.  
  265.         shotcount = shotcount - 1;
  266.     }
  267.     ApplyMultiDamage ();
  268. };
  269.  
  270. /*
  271. ================
  272. W_FireShotgun
  273. ================
  274. */
  275. void() W_FireShotgun =
  276. {
  277.     local vector dir;
  278.  
  279.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  280.  
  281.     self.punchangle_x = -2;
  282.     
  283.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  284.     dir = aim (self, 100000);
  285.     FireBullets (6, dir, '0.04 0.04 0');
  286. };
  287.  
  288.  
  289. /*
  290. ================
  291. W_FireSuperShotgun
  292. ================
  293. */
  294. void() W_FireSuperShotgun =
  295. {
  296.     local vector dir;
  297.  
  298.     if (self.currentammo == 1)
  299.     {
  300.         W_FireShotgun ();
  301.         return;
  302.     }
  303.         
  304.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  305.  
  306.     self.punchangle_x = -4;
  307.     
  308.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  309.     dir = aim (self, 100000);
  310.     FireBullets (14, dir, '0.14 0.08 0');
  311. };
  312.  
  313.  
  314. /*
  315. ==============================================================================
  316.  
  317. ROCKETS
  318.  
  319. ==============================================================================
  320. */
  321.  
  322. void()    s_explode1    =    [0,        s_explode2] {};
  323. void()    s_explode2    =    [1,        s_explode3] {};
  324. void()    s_explode3    =    [2,        s_explode4] {};
  325. void()    s_explode4    =    [3,        s_explode5] {};
  326. void()    s_explode5    =    [4,        s_explode6] {};
  327. void()    s_explode6    =    [5,        SUB_Remove] {};
  328.  
  329. void() BecomeExplosion =
  330. {
  331.     self.movetype = MOVETYPE_NONE;
  332.     self.velocity = '0 0 0';
  333.     self.touch = SUB_Null;
  334.     setmodel (self, "progs/s_explod.spr");
  335.     self.solid = SOLID_NOT;
  336.     s_explode1 ();
  337. };
  338.  
  339. void() T_MissileTouch =
  340. {
  341.     local float    damg;
  342.  
  343.     if (other == self.owner)
  344.         return;        // don't explode on owner
  345.  
  346.     if (pointcontents(self.origin) == CONTENT_SKY)
  347.     {
  348.         remove(self);
  349.         return;
  350.     }
  351.  
  352.     damg = 100 + random()*20;
  353.     
  354.     if (other.health)
  355.     {
  356.         if (other.classname == "monster_shambler")
  357.             damg = damg * 0.5;    // mostly immune
  358.         T_Damage (other, self, self.owner, damg );
  359.     }
  360.  
  361.     // don't do radius damage to the other, because all the damage
  362.     // was done in the impact
  363.     T_RadiusDamage (self, self.owner, 120, other);
  364.  
  365. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  366.     self.origin = self.origin - 8*normalize(self.velocity);
  367.  
  368.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  369.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  370.     WriteCoord (MSG_BROADCAST, self.origin_x);
  371.     WriteCoord (MSG_BROADCAST, self.origin_y);
  372.     WriteCoord (MSG_BROADCAST, self.origin_z);
  373.  
  374.     BecomeExplosion ();
  375. };
  376.  
  377.  
  378.  
  379. /*
  380. ================
  381. W_FireRocket
  382. ================
  383. */
  384. void() W_FireRocket =
  385. {
  386.     local    entity missile, mpuff;
  387.     
  388.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  389.     
  390.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  391.  
  392.     self.punchangle_x = -2;
  393.  
  394.     missile = spawn ();
  395.     missile.owner = self;
  396.     missile.movetype = MOVETYPE_FLYMISSILE;
  397.     missile.solid = SOLID_BBOX;
  398.     missile.classname = "missile";
  399.         
  400. // set missile speed    
  401.  
  402.     makevectors (self.v_angle);
  403.     missile.velocity = aim(self, 1000);
  404.     missile.velocity = missile.velocity * 1000;
  405.     missile.angles = vectoangles(missile.velocity);
  406.     
  407.     missile.touch = T_MissileTouch;
  408.     
  409. // set missile duration
  410.     missile.nextthink = time + 5;
  411.     missile.think = SUB_Remove;
  412.  
  413.     setmodel (missile, "progs/missile.mdl");
  414.     setsize (missile, '0 0 0', '0 0 0');        
  415.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  416. };
  417.  
  418. /*
  419. ===============================================================================
  420.  
  421. LIGHTNING
  422.  
  423. ===============================================================================
  424. */
  425.  
  426. /*
  427. =================
  428. LightningDamage
  429. =================
  430. */
  431. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  432. {
  433.     local entity        e1, e2;
  434.     local vector        f;
  435.     
  436.     f = p2 - p1;
  437.     normalize (f);
  438.     f_x = 0 - f_y;
  439.     f_y = f_x;
  440.     f_z = 0;
  441.     f = f*16;
  442.  
  443.     e1 = e2 = world;
  444.  
  445.     traceline (p1, p2, FALSE, self);
  446.     if (trace_ent.takedamage)
  447.     {
  448.         particle (trace_endpos, '0 0 100', 225, damage*4);
  449.         T_Damage (trace_ent, from, from, damage);
  450.         if (self.classname == "player")
  451.         {
  452.             if (other.classname == "player")
  453.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  454.         }
  455.     }
  456.     e1 = trace_ent;
  457.  
  458.     traceline (p1 + f, p2 + f, FALSE, self);
  459.     if (trace_ent != e1 && trace_ent.takedamage)
  460.     {
  461.         particle (trace_endpos, '0 0 100', 225, damage*4);
  462.         T_Damage (trace_ent, from, from, damage);
  463.     }
  464.     e2 = trace_ent;
  465.  
  466.     traceline (p1 - f, p2 - f, FALSE, self);
  467.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  468.     {
  469.         particle (trace_endpos, '0 0 100', 225, damage*4);
  470.         T_Damage (trace_ent, from, from, damage);
  471.     }
  472. };
  473.  
  474.  
  475. void() W_FireLightning =
  476. {
  477.     local    vector        org;
  478.     local    float        cells;
  479.  
  480.     if (self.ammo_cells < 1)
  481.     {
  482.         self.weapon = W_BestWeapon ();
  483.         W_SetCurrentAmmo ();
  484.         return;
  485.     }
  486.  
  487. // explode if under water
  488.     if (self.waterlevel > 1)
  489.     {
  490.         cells = self.ammo_cells;
  491.         self.ammo_cells = 0;
  492.         W_SetCurrentAmmo ();
  493.         T_RadiusDamage (self, self, 35*cells, world);
  494.         return;
  495.     }
  496.  
  497.     if (self.t_width < time)
  498.     {
  499.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  500.         self.t_width = time + 0.6;
  501.     }
  502.     self.punchangle_x = -2;
  503.  
  504.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  505.  
  506.     org = self.origin + '0 0 16';
  507.     
  508.     traceline (org, org + v_forward*600, TRUE, self);
  509.  
  510.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  511.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  512.     WriteEntity (MSG_BROADCAST, self);
  513.     WriteCoord (MSG_BROADCAST, org_x);
  514.     WriteCoord (MSG_BROADCAST, org_y);
  515.     WriteCoord (MSG_BROADCAST, org_z);
  516.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  517.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  518.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  519.  
  520.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  521. };
  522.  
  523.  
  524. //=============================================================================
  525.  
  526.  
  527. void() GrenadeExplode =
  528. {
  529.     T_RadiusDamage (self, self.owner, 120, world);
  530.  
  531.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  532.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  533.     WriteCoord (MSG_BROADCAST, self.origin_x);
  534.     WriteCoord (MSG_BROADCAST, self.origin_y);
  535.     WriteCoord (MSG_BROADCAST, self.origin_z);
  536.  
  537.     BecomeExplosion ();
  538. };
  539.  
  540. void() GrenadeTouch =
  541. {
  542.     if (other == self.owner)
  543.         return;        // don't explode on owner
  544.     if (other.takedamage == DAMAGE_AIM)
  545.     {
  546.         GrenadeExplode();
  547.         return;
  548.     }
  549.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  550.     if (self.velocity == '0 0 0')
  551.         self.avelocity = '0 0 0';
  552. };
  553.  
  554. /*
  555. ================
  556. W_FireGrenade
  557. ================
  558. */
  559. void() W_FireGrenade =
  560. {
  561.     local    entity missile, mpuff;
  562.     
  563.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  564.     
  565.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  566.  
  567.     self.punchangle_x = -2;
  568.  
  569.     missile = spawn ();
  570.     missile.owner = self;
  571.     missile.movetype = MOVETYPE_BOUNCE;
  572.     missile.solid = SOLID_BBOX;
  573.     missile.classname = "grenade";
  574.         
  575. // set missile speed    
  576.  
  577.     makevectors (self.v_angle);
  578.  
  579.     if (self.v_angle_x)
  580.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  581.     else
  582.     {
  583.         missile.velocity = aim(self, 10000);
  584.         missile.velocity = missile.velocity * 600;
  585.         missile.velocity_z = 200;
  586.     }
  587.  
  588.     missile.avelocity = '300 300 300';
  589.  
  590.     missile.angles = vectoangles(missile.velocity);
  591.     
  592.     missile.touch = GrenadeTouch;
  593.     
  594. // set missile duration
  595.     missile.nextthink = time + 2.5;
  596.     missile.think = GrenadeExplode;
  597.  
  598.     setmodel (missile, "progs/grenade.mdl");
  599.     setsize (missile, '0 0 0', '0 0 0');        
  600.     setorigin (missile, self.origin);
  601. };
  602.  
  603.  
  604. //=============================================================================
  605.  
  606. void() spike_touch;
  607. void() superspike_touch;
  608.  
  609.  
  610. /*
  611. ===============
  612. launch_spike
  613.  
  614. Used for both the player and the ogre
  615. ===============
  616. */
  617. void(vector org, vector dir) launch_spike =
  618. {
  619.     newmis = spawn ();
  620.     newmis.owner = self;
  621.     newmis.movetype = MOVETYPE_FLYMISSILE;
  622.     newmis.solid = SOLID_BBOX;
  623.  
  624.     newmis.angles = vectoangles(dir);
  625.     
  626.     newmis.touch = spike_touch;
  627.     newmis.classname = "spike";
  628.     newmis.think = SUB_Remove;
  629.     newmis.nextthink = time + 6;
  630.     setmodel (newmis, "progs/spike.mdl");
  631.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  632.     setorigin (newmis, org);
  633.  
  634.     newmis.velocity = dir * 1000;
  635. };
  636.  
  637. void() W_FireSuperSpikes =
  638. {
  639.     local vector    dir;
  640.     local entity    old;
  641.     
  642.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  643.     self.attack_finished = time + 0.2;
  644.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  645.     dir = aim (self, 1000);
  646.     launch_spike (self.origin + '0 0 16', dir);
  647.     newmis.touch = superspike_touch;
  648.     setmodel (newmis, "progs/s_spike.mdl");
  649.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  650.     self.punchangle_x = -2;
  651. };
  652.  
  653. void(float ox) W_FireSpikes =
  654. {
  655.     local vector    dir;
  656.     local entity    old;
  657.     
  658.     makevectors (self.v_angle);
  659.     
  660.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  661.     {
  662.         W_FireSuperSpikes ();
  663.         return;
  664.     }
  665.  
  666.     if (self.ammo_nails < 1)
  667.     {
  668.         self.weapon = W_BestWeapon ();
  669.         W_SetCurrentAmmo ();
  670.         return;
  671.     }
  672.  
  673.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  674.     self.attack_finished = time + 0.2;
  675.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  676.     dir = aim (self, 1000);
  677.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  678.  
  679.     self.punchangle_x = -2;
  680. };
  681.  
  682.  
  683.  
  684. .float hit_z;
  685. void() spike_touch =
  686. {
  687. local float rand;
  688.     if (other == self.owner)
  689.         return;
  690.  
  691.     if (other.solid == SOLID_TRIGGER)
  692.         return;    // trigger field, do nothing
  693.  
  694.     if (pointcontents(self.origin) == CONTENT_SKY)
  695.     {
  696.         remove(self);
  697.         return;
  698.     }
  699.     
  700. // hit something that bleeds
  701.     if (other.takedamage)
  702.     {
  703.         spawn_touchblood (9);
  704.         T_Damage (other, self, self.owner, 9);
  705.     }
  706.     else
  707.     {
  708.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  709.         
  710.         if (self.classname == "wizspike")
  711.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  712.         else if (self.classname == "knightspike")
  713.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  714.         else
  715.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  716.         WriteCoord (MSG_BROADCAST, self.origin_x);
  717.         WriteCoord (MSG_BROADCAST, self.origin_y);
  718.         WriteCoord (MSG_BROADCAST, self.origin_z);
  719.     }
  720.  
  721.     remove(self);
  722.  
  723. };
  724.  
  725. void() superspike_touch =
  726. {
  727. local float rand;
  728.     if (other == self.owner)
  729.         return;
  730.  
  731.     if (other.solid == SOLID_TRIGGER)
  732.         return;    // trigger field, do nothing
  733.  
  734.     if (pointcontents(self.origin) == CONTENT_SKY)
  735.     {
  736.         remove(self);
  737.         return;
  738.     }
  739.     
  740. // hit something that bleeds
  741.     if (other.takedamage)
  742.     {
  743.         spawn_touchblood (18);
  744.         T_Damage (other, self, self.owner, 18);
  745.     }
  746.     else
  747.     {
  748.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  749.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  750.         WriteCoord (MSG_BROADCAST, self.origin_x);
  751.         WriteCoord (MSG_BROADCAST, self.origin_y);
  752.         WriteCoord (MSG_BROADCAST, self.origin_z);
  753.     }
  754.  
  755.     remove(self);
  756.  
  757. };
  758.  
  759.  
  760. /*
  761. ===============================================================================
  762.  
  763. PLAYER WEAPON USE
  764.  
  765. ===============================================================================
  766. */
  767.  
  768. void() W_SetCurrentAmmo =
  769. {
  770.     player_run ();        // get out of any weapon firing states
  771.  
  772.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  773.     
  774.     if (self.weapon == IT_AXE)
  775.     {
  776.         self.currentammo = 0;
  777.         self.weaponmodel = "progs/v_axe.mdl";
  778.         self.weaponframe = 0;
  779.     }
  780.     else if (self.weapon == IT_SHOTGUN)
  781.     {
  782.         self.currentammo = self.ammo_shells;
  783.         self.weaponmodel = "progs/v_shot.mdl";
  784.         self.weaponframe = 0;
  785.         self.items = self.items | IT_SHELLS;
  786.     }
  787.     else if (self.weapon == IT_SUPER_SHOTGUN)
  788.     {
  789.         self.currentammo = self.ammo_shells;
  790.         self.weaponmodel = "progs/v_shot2.mdl";
  791.         self.weaponframe = 0;
  792.         self.items = self.items | IT_SHELLS;
  793.     }
  794.     else if (self.weapon == IT_NAILGUN)
  795.     {
  796.         self.currentammo = self.ammo_nails;
  797.         self.weaponmodel = "progs/v_nail.mdl";
  798.         self.weaponframe = 0;
  799.         self.items = self.items | IT_NAILS;
  800.     }
  801.     else if (self.weapon == IT_SUPER_NAILGUN)
  802.     {
  803.         self.currentammo = self.ammo_nails;
  804.         self.weaponmodel = "progs/v_nail2.mdl";
  805.         self.weaponframe = 0;
  806.         self.items = self.items | IT_NAILS;
  807.     }
  808.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  809.     {
  810.         self.currentammo = self.ammo_rockets;
  811.         self.weaponmodel = "progs/v_rock.mdl";
  812.         self.weaponframe = 0;
  813.         self.items = self.items | IT_ROCKETS;
  814.     }
  815.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  816.     {
  817.         self.currentammo = self.ammo_rockets;
  818.         self.weaponmodel = "progs/v_rock2.mdl";
  819.         self.weaponframe = 0;
  820.         self.items = self.items | IT_ROCKETS;
  821.     }
  822.     else if (self.weapon == IT_LIGHTNING)
  823.     {
  824.         self.currentammo = self.ammo_cells;
  825.         self.weaponmodel = "progs/v_light.mdl";
  826.         self.weaponframe = 0;
  827.         self.items = self.items | IT_CELLS;
  828.     }
  829.     else
  830.     {
  831.         self.currentammo = 0;
  832.         self.weaponmodel = "";
  833.         self.weaponframe = 0;
  834.     }
  835.  
  836.    // ### chasecam mod ###
  837.    // disable model in chase view
  838.     if ( (self.dest2_x & CHSCAM_ON) )
  839.     {
  840.         self.weaponmodel = "";
  841.         HUD_print_info(1);
  842.     }
  843. };
  844.  
  845. float() W_BestWeapon =
  846. {
  847.     local    float    it;
  848.     
  849.     it = self.items;
  850.  
  851.     if (self.waterlevel <= 1 && self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  852.             return IT_LIGHTNING;
  853.     if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  854.         return IT_SUPER_NAILGUN;
  855.     if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  856.         return IT_SUPER_SHOTGUN;
  857.     if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  858.         return IT_NAILGUN;
  859.     if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  860.         return IT_SHOTGUN;
  861.     return IT_AXE;
  862. };
  863.  
  864. float() W_CheckNoAmmo =
  865. {
  866.     if (self.currentammo > 0)
  867.         return TRUE;
  868.  
  869.     if (self.weapon == IT_AXE)
  870.         return TRUE;
  871.     
  872.     self.weapon = W_BestWeapon ();
  873.  
  874.     W_SetCurrentAmmo ();
  875.     
  876. // drop the weapon down
  877.     return FALSE;
  878. };
  879.  
  880. /*
  881. ============
  882. W_Attack
  883.  
  884. An attack impulse can be triggered now
  885. ============
  886. */
  887. void()    player_axe1;
  888. void()    player_axeb1;
  889. void()    player_axec1;
  890. void()    player_axed1;
  891. void()    player_shot1;
  892. void()    player_nail1;
  893. void()    player_light1;
  894. void()    player_rocket1;
  895.  
  896. void() W_Attack =
  897. {
  898.     local    float    r;
  899.  
  900.     if (!W_CheckNoAmmo ())
  901.         return;
  902.  
  903.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  904.     self.show_hostile = time + 1;    // wake monsters up
  905.  
  906.     if (self.weapon == IT_AXE)
  907.     {
  908.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  909.         r = random();
  910.         if (r < 0.25)
  911.             player_axe1 ();
  912.         else if (r<0.5)
  913.             player_axeb1 ();
  914.         else if (r<0.75)
  915.             player_axec1 ();
  916.         else
  917.             player_axed1 ();
  918.         self.attack_finished = time + 0.5;
  919.     }
  920.     else if (self.weapon == IT_SHOTGUN)
  921.     {
  922.         player_shot1 ();
  923.         W_FireShotgun ();
  924.         self.attack_finished = time + 0.5;
  925.     }
  926.     else if (self.weapon == IT_SUPER_SHOTGUN)
  927.     {
  928.         player_shot1 ();
  929.         W_FireSuperShotgun ();
  930.         self.attack_finished = time + 0.7;
  931.     }
  932.     else if (self.weapon == IT_NAILGUN)
  933.     {
  934.         player_nail1 ();
  935.     }
  936.     else if (self.weapon == IT_SUPER_NAILGUN)
  937.     {
  938.         player_nail1 ();
  939.     }
  940.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  941.     {
  942.         player_rocket1();
  943.         W_FireGrenade();
  944.         self.attack_finished = time + 0.6;
  945.     }
  946.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  947.     {
  948.         player_rocket1();
  949.         W_FireRocket();
  950.         self.attack_finished = time + 0.8;
  951.     }
  952.     else if (self.weapon == IT_LIGHTNING)
  953.     {
  954.         player_light1();
  955.         self.attack_finished = time + 0.1;
  956.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  957.     }
  958. };
  959.  
  960. /*
  961. ============
  962. W_ChangeWeapon
  963.  
  964. ============
  965. */
  966. void() W_ChangeWeapon =
  967. {
  968.     local    float    it, am, fl;
  969.     
  970.     it = self.items;
  971.     am = 0;
  972.     
  973.     if (self.impulse == 1)
  974.     {
  975.         fl = IT_AXE;
  976.     }
  977.     else if (self.impulse == 2)
  978.     {
  979.         fl = IT_SHOTGUN;
  980.         if (self.ammo_shells < 1)
  981.             am = 1;
  982.     }
  983.     else if (self.impulse == 3)
  984.     {
  985.         fl = IT_SUPER_SHOTGUN;
  986.         if (self.ammo_shells < 2)
  987.             am = 1;
  988.     }        
  989.     else if (self.impulse == 4)
  990.     {
  991.         fl = IT_NAILGUN;
  992.         if (self.ammo_nails < 1)
  993.             am = 1;
  994.     }
  995.     else if (self.impulse == 5)
  996.     {
  997.         fl = IT_SUPER_NAILGUN;
  998.         if (self.ammo_nails < 2)
  999.             am = 1;
  1000.     }
  1001.     else if (self.impulse == 6)
  1002.     {
  1003.         fl = IT_GRENADE_LAUNCHER;
  1004.         if (self.ammo_rockets < 1)
  1005.             am = 1;
  1006.     }
  1007.     else if (self.impulse == 7)
  1008.     {
  1009.         fl = IT_ROCKET_LAUNCHER;
  1010.         if (self.ammo_rockets < 1)
  1011.             am = 1;
  1012.     }
  1013.     else if (self.impulse == 8)
  1014.     {
  1015.         fl = IT_LIGHTNING;
  1016.         if (self.ammo_cells < 1)
  1017.             am = 1;
  1018.     }
  1019.  
  1020.     self.impulse = 0;
  1021.     
  1022.     if (!(self.items & fl))
  1023.     {    // don't have the weapon or the ammo
  1024.         sprint (self, "no weapon.\n");
  1025.         return;
  1026.     }
  1027.     
  1028.     if (am)
  1029.     {    // don't have the ammo
  1030.         sprint (self, "not enough ammo.\n");
  1031.         return;
  1032.     }
  1033.  
  1034. //
  1035. // set weapon, set ammo
  1036. //
  1037.     self.weapon = fl;        
  1038.     W_SetCurrentAmmo ();
  1039. };
  1040.  
  1041. /*
  1042. ============
  1043. CheatCommand
  1044. ============
  1045. */
  1046. void() CheatCommand =
  1047. {
  1048.     if (deathmatch || coop)
  1049.         return;
  1050.  
  1051.     self.ammo_rockets = 100;
  1052.     self.ammo_nails = 200;
  1053.     self.ammo_shells = 100;
  1054.     self.items = self.items | 
  1055.         IT_AXE |
  1056.         IT_SHOTGUN |
  1057.         IT_SUPER_SHOTGUN |
  1058.         IT_NAILGUN |
  1059.         IT_SUPER_NAILGUN |
  1060.         IT_GRENADE_LAUNCHER |
  1061.         IT_ROCKET_LAUNCHER |
  1062.         IT_KEY1 | IT_KEY2;
  1063.  
  1064.     self.ammo_cells = 200;
  1065.     self.items = self.items | IT_LIGHTNING;
  1066.  
  1067.     self.weapon = IT_ROCKET_LAUNCHER;
  1068.     self.impulse = 0;
  1069.     W_SetCurrentAmmo ();
  1070. };
  1071.  
  1072. /*
  1073. ============
  1074. CycleWeaponCommand
  1075.  
  1076. Go to the next weapon with ammo
  1077. ============
  1078. */
  1079. void() CycleWeaponCommand =
  1080. {
  1081.     local    float    it, am;
  1082.     
  1083.     it = self.items;
  1084.     self.impulse = 0;
  1085.     
  1086.     while (1)
  1087.     {
  1088.         am = 0;
  1089.  
  1090.         if (self.weapon == IT_LIGHTNING)
  1091.         {
  1092.             self.weapon = IT_AXE;
  1093.         }
  1094.         else if (self.weapon == IT_AXE)
  1095.         {
  1096.             self.weapon = IT_SHOTGUN;
  1097.             if (self.ammo_shells < 1)
  1098.                 am = 1;
  1099.         }
  1100.         else if (self.weapon == IT_SHOTGUN)
  1101.         {
  1102.             self.weapon = IT_SUPER_SHOTGUN;
  1103.             if (self.ammo_shells < 2)
  1104.                 am = 1;
  1105.         }        
  1106.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1107.         {
  1108.             self.weapon = IT_NAILGUN;
  1109.             if (self.ammo_nails < 1)
  1110.                 am = 1;
  1111.         }
  1112.         else if (self.weapon == IT_NAILGUN)
  1113.         {
  1114.             self.weapon = IT_SUPER_NAILGUN;
  1115.             if (self.ammo_nails < 2)
  1116.                 am = 1;
  1117.         }
  1118.         else if (self.weapon == IT_SUPER_NAILGUN)
  1119.         {
  1120.             self.weapon = IT_GRENADE_LAUNCHER;
  1121.             if (self.ammo_rockets < 1)
  1122.                 am = 1;
  1123.         }
  1124.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1125.         {
  1126.             self.weapon = IT_ROCKET_LAUNCHER;
  1127.             if (self.ammo_rockets < 1)
  1128.                 am = 1;
  1129.         }
  1130.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1131.         {
  1132.             self.weapon = IT_LIGHTNING;
  1133.             if (self.ammo_cells < 1)
  1134.                 am = 1;
  1135.         }
  1136.     
  1137.         if ( (it & self.weapon) && am == 0)
  1138.         {
  1139.             W_SetCurrentAmmo ();
  1140.             return;
  1141.         }
  1142.     }
  1143.  
  1144. };
  1145.  
  1146. /*
  1147. ============
  1148. CycleWeaponReverseCommand
  1149.  
  1150. Go to the prev weapon with ammo
  1151. ============
  1152. */
  1153. void() CycleWeaponReverseCommand =
  1154. {
  1155.     local    float    it, am;
  1156.     
  1157.     it = self.items;
  1158.     self.impulse = 0;
  1159.  
  1160.     while (1)
  1161.     {
  1162.         am = 0;
  1163.  
  1164.         if (self.weapon == IT_LIGHTNING)
  1165.         {
  1166.             self.weapon = IT_ROCKET_LAUNCHER;
  1167.             if (self.ammo_rockets < 1)
  1168.                 am = 1;
  1169.         }
  1170.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1171.         {
  1172.             self.weapon = IT_GRENADE_LAUNCHER;
  1173.             if (self.ammo_rockets < 1)
  1174.                 am = 1;
  1175.         }
  1176.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1177.         {
  1178.             self.weapon = IT_SUPER_NAILGUN;
  1179.             if (self.ammo_nails < 2)
  1180.                 am = 1;
  1181.         }
  1182.         else if (self.weapon == IT_SUPER_NAILGUN)
  1183.         {
  1184.             self.weapon = IT_NAILGUN;
  1185.             if (self.ammo_nails < 1)
  1186.                 am = 1;
  1187.         }
  1188.         else if (self.weapon == IT_NAILGUN)
  1189.         {
  1190.             self.weapon = IT_SUPER_SHOTGUN;
  1191.             if (self.ammo_shells < 2)
  1192.                 am = 1;
  1193.         }        
  1194.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1195.         {
  1196.             self.weapon = IT_SHOTGUN;
  1197.             if (self.ammo_shells < 1)
  1198.                 am = 1;
  1199.         }
  1200.         else if (self.weapon == IT_SHOTGUN)
  1201.         {
  1202.             self.weapon = IT_AXE;
  1203.         }
  1204.         else if (self.weapon == IT_AXE)
  1205.         {
  1206.             self.weapon = IT_LIGHTNING;
  1207.             if (self.ammo_cells < 1)
  1208.                 am = 1;
  1209.         }
  1210.     
  1211.         if ( (it & self.weapon) && am == 0)
  1212.         {
  1213.             W_SetCurrentAmmo ();
  1214.             return;
  1215.         }
  1216.     }
  1217.  
  1218. };
  1219.  
  1220. /*
  1221. ============
  1222. ServerflagsCommand
  1223.  
  1224. Just for development
  1225. ============
  1226. */
  1227. void() ServerflagsCommand =
  1228. {
  1229.     serverflags = serverflags * 2 + 1;
  1230. };
  1231.  
  1232. void() QuadCheat =
  1233. {
  1234.     if (deathmatch || coop)
  1235.         return;
  1236.     self.super_time = 1;
  1237.     self.super_damage_finished = time + 30;
  1238.     self.items = self.items | IT_QUAD;
  1239.     dprint ("quad cheat\n");
  1240. };
  1241.  
  1242. /*
  1243. ============
  1244. ImpulseCommands
  1245.  
  1246. ============
  1247. */
  1248. void() ImpulseCommands =
  1249. {
  1250.     if (self.impulse >= 1 && self.impulse <= 8)
  1251.         W_ChangeWeapon ();
  1252.  
  1253.     if (self.impulse == 9)
  1254.         CheatCommand ();
  1255.     if (self.impulse == 10)
  1256.         CycleWeaponCommand ();
  1257.     if (self.impulse == 11)
  1258.         ServerflagsCommand ();
  1259.     if (self.impulse == 12)
  1260.         CycleWeaponReverseCommand ();
  1261.  
  1262.     // ### chasecam mod ###
  1263.     else if (self.impulse == 30) Toggle_chase_cam();
  1264.     else if (self.impulse == 31) LaserTargeterToggle( self );
  1265.  
  1266.     else if (self.impulse == 32) Chase_cam_change_zmult(0); // minus
  1267.     else if (self.impulse == 33) Chase_cam_change_zmult(1); // plus
  1268.     else if (self.impulse == 34) Chase_cam_change_dist(0); // minus
  1269.     else if (self.impulse == 35) Chase_cam_change_dist(1); // plus
  1270.  
  1271.     else if (self.impulse == 38) Chase_cam_read_temp1(0); // read cvar temp1 into player.dest2_y (cam distance)
  1272.     else if (self.impulse == 39) Chase_cam_read_temp1(1); // read cvar temp1 into player.dest2_z (cam height)
  1273.  
  1274.     // ### hot key weapon mod ###
  1275.     else if (self.impulse == 40) HotKey_previous_weapon();
  1276.     else if (self.impulse == 41) HotKey_weapon(1); // axe
  1277.     else if (self.impulse == 42) HotKey_weapon(2); // grenade
  1278.     else if (self.impulse == 43) HotKey_weapon(3); // rocket
  1279.     else if (self.impulse == 44) HotKey_CycleWeaponReverseCommand();
  1280.     else if (self.impulse == 45) HotKey_CycleWeaponCommand();
  1281.  
  1282.     // ### HUD mod ###
  1283.     else if (self.impulse == 50)
  1284.     {    // once player selects, turned on until full client reset
  1285.         if (! (self.dest2_x & HUD_ON) )
  1286.             self.dest2_x = self.dest2_x | HUD_ON;
  1287.         HUD_print_info(1);
  1288.     }
  1289.     // ### Swinging hook mod ###
  1290.     else if (self.impulse >= 95 && self.impulse <= 98)
  1291.         CheckGrapHook ();
  1292.     // ### Multiskin Pro mod ###
  1293.     else if (self.impulse == 200) Choose_multiskin(1);
  1294.     else if (self.impulse == 201) Choose_multiskin(0);
  1295.  
  1296.  
  1297.  
  1298.     if (self.impulse == 255)
  1299.         QuadCheat ();
  1300.  
  1301.     self.impulse = 0;
  1302. };
  1303.  
  1304. /*
  1305. ============
  1306. W_WeaponFrame
  1307.  
  1308. Called every frame so impulse events can be handled as well as possible
  1309. ============
  1310. */
  1311. void() W_WeaponFrame =
  1312. {
  1313.     // ### chasecam mod ###
  1314.  
  1315.     if (self.dest1_x != self.health)
  1316.         HUD_print_info(0);
  1317.  
  1318.    // Let hook get it's scan of jump events
  1319.     if (self.button2)
  1320.         CheckGrapHook ();
  1321.  
  1322.     if (time < self.attack_finished)
  1323.         return;
  1324.  
  1325.     if (self.impulse != 0)
  1326.         ImpulseCommands ();
  1327.  
  1328. // check for attack
  1329.     if (self.button0)
  1330.     {
  1331.         SuperDamageSound ();
  1332.         W_Attack ();
  1333.     }
  1334. };
  1335.  
  1336. /*
  1337. ========
  1338. SuperDamageSound
  1339.  
  1340. Plays sound if needed
  1341. ========
  1342. */
  1343. void() SuperDamageSound =
  1344. {
  1345.     if (self.super_damage_finished > time)
  1346.     {
  1347.         if (self.super_sound < time)
  1348.         {
  1349.             self.super_sound = time + 1;
  1350.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1351.         }
  1352.     }
  1353.     return;
  1354. };
  1355.  
  1356.  
  1357.